forum

Home / DeveloperSection / Forums / Error in Coloring Datagridview Row in c#

Error in Coloring Datagridview Row in c#

Anonymous User 1942 18-Aug-2014

I have a datageidview which supposed to color the rows with contains specific value

    private void dataGridView2_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
    {
        foreach (DataGridViewRow myrow in dataGridView2.Rows)
        {
            if (e.RowIndex != -1)
            {
                    if (myrow.Cells[7].Value.ToString() == "Error")
                    {
                        myrow.DefaultCellStyle.BackColor = Color.Red;
                    }
                    else if (myrow.Cells[7].Value.ToString() == "NoError")
                    {
                        myrow.DefaultCellStyle.BackColor = Color.Green;
                    }
                }
        }
    }

but i have a problem when the first row contains this value all the rows is colored with it's color

any help ??


c# c# 
Updated on 18-Aug-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By